package cn.tx.sboot;

import cn.tx.sboot.utils.FileIoUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
public class TestController {
    @RequestMapping("category")
    public String hello() {
        String content = FileIoUtils.readResources("newsCategory.json");
        return content;
    }

    /**
     * 推荐
     *
     * @return
     */
    @RequestMapping("comment")
    public String comment() {
        String content = FileIoUtils.readResources("commentNew.json");
        return content;
    }

    /**
     * 热搜
     *
     * @return
     */
    @RequestMapping("hot")
    public String hot() {
        String content = FileIoUtils.readResources("hotNew.json");
        return content;
    }

    @RequestMapping(value = "test/post", method = RequestMethod.POST)
    public String testPost(@RequestBody String param) {
        System.out.println(param);
        return "hello";
    }

    /**
     * 多文件上传
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/test/multipart", method = RequestMethod.POST)
    @ResponseBody
    public String multipart(HttpServletRequest request) {
        MultipartHttpServletRequest params=((MultipartHttpServletRequest) request);
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
        String p1 = request.getParameter("params1");
        String p2 = request.getParameter("params2");
        System.out.println(p1 + "   " + p2);
        return "hello";
    }
}


